package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
)

type PageController struct {
	beego.Controller
}

// session session处理
func (c *PageController) session(path string) {
	contact, ok := GetSessionContact(c.GetSession("Contact"))
	if ok {
		c.Data["UserName"] = contact.ContactName
		c.TplName = path
	} else {
		c.Redirect("/page/err400", 302)
	}
}

// LoginPage 登录
func (c *PageController) LoginPage() {
	c.TplName = "login.tpl"
}

// RegisterPage 注册
func (c *PageController) RegisterPage() {
	c.TplName = "register.tpl"
}

// MainPage 主页
func (c *PageController) MainPage() {
	c.session("sys/main_page.tpl")
}

// CustomerPage 基本信息
func (c *PageController) CustomerPage() {
	c.session("sys/customer.tpl")
}

// CustomerViewPage 客户详细信息
func (c *PageController) CustomerViewPage() {
	id, err := c.GetInt(":id")
	err = c.SetSession("customerID", id)
	if err != nil {
		c.Data["json"] = Status{ErrCode: GET_OK, Msg: "customer success"}
		c.ServeJSON()
		c.StopRun()
	}
	c.session("sys/customer_view.tpl")
}

// ContactChangePage 用户信息
func (c *PageController) ContactChangePage() {
	c.session("sys/contact_changepassword.tpl")
}

// LostCustomerPage 流失客户信息
func (c *PageController) LostCustomerPage() {
	c.session("sys/customer_lost.tpl")
}

// CustomerLostViewPage 流失客户详细信息
func (c *PageController) CustomerLostViewPage() {
	id, err := c.GetInt(":id")
	err = c.SetSession("customerID", id)
	if err != nil {
		c.Data["json"] = Status{ErrCode: GET_OK, Msg: "customer success"}
		c.ServeJSON()
		c.StopRun()
	}
	c.session("sys/customer_lost_view.tpl")
}

// BillPage 账单信息
func (c *PageController) BillPage() {
	c.session("sys/order.tpl")
}

// ServicePage 服务信息
func (c *PageController) ServicePage() {
	c.session("sys/service_view.tpl")

}

// ServiceAddPage 添加服务
func (c *PageController) ServiceAddPage() {
	c.session("sys/service_add.tpl")

}

// MarkingOppPage 营销机会
func (c *PageController) MarkingOppPage() {
	c.session("sys/marketing_opportunities.tpl")

}

// CustomerPlansPage 客户计划
func (c *PageController) CustomerPlansPage() {
	c.session("sys/customer_development_plans.tpl")

}

// Err400Page err400
func (c *PageController) Err400Page() {
	c.TplName = "sys/errorpage/pages-error.html"
}

// Err500Page err500
func (c *PageController) Err500Page() {
	c.TplName = "sys/errorpage/pages-error-500.html"
}
